﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T12OOP
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 类与其构造函数
            Account acc1 = new Account();
            Console.WriteLine(acc1);
            Account acc2 = new Account("张达平",100000);
            Console.WriteLine(acc2);
            #endregion

            #region 单例模式
            SingleTon s1= SingleTon.GetInstance();
            SingleTon s2 = SingleTon.GetInstance();
            if (s1 == s2)
            {
                Console.WriteLine("Single类的两个实例是一样的");
            }
            #endregion

            #region 属性
            Student stu = new Student();
            stu.Name = "张三";
            //异常处理：友好的对待有可能出现的错误
            try
            {
                stu.Age = 21;
                stu.Age = -21;

            }
            catch (Exception)
            {

                Console.WriteLine("年龄不能超过指定范围");
            }

            Console.WriteLine(stu);
            #endregion

            #region 索引属性
            Contact c = new Contact("张三");
            //c.Name = "只读属性不能赋值";
            Console.WriteLine(c.Name); 
            c["mobile"] = "125555251"; 
            c["home" ]= "0792-54646";
            c[ "fax"]= "+086-556555";
            c["business"]= "0792-65512";
            Console.WriteLine(c);
            #endregion

            #region 预定义操作符
            GameValue gv1 = new GameValue();
            gv1.Hp = 40;
            gv1.Mp = 50;
            gv1.Sp = 20;
            GameValue gv2 = new GameValue();
            gv2.Hp = 30;
            gv2.Mp = 30;
            gv2.Sp = 10;
            Console.WriteLine(gv1);
            gv1=gv1+  gv2;
            Console.WriteLine(gv1);
            #endregion
            Console.ReadKey();
        }
    }
}
